feat(security): add detection rules for destructive shell commands#1484
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the security posture by expanding the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR expands the tool-guard’s built-in YAML ruleset for execute_shell_command to detect and gate a wider set of destructive, privilege-escalating, obfuscated, and suspicious shell command patterns, reducing the chance an agent executes high-risk commands without user intervention.
Changes:
- Added new detection rules for filesystem/device destruction, destructive Git operations, fork bombs/DoS, pipe-to-shell downloaders, reverse shells, system tampering, unsafe permissions, and base64-obfuscated execution.
- Assigned severities/categories and provided user-facing remediation guidance per rule.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable set of new detection rules for various dangerous shell commands, significantly enhancing the security posture of the tool guard. The rules are well-structured and cover a wide range of threats, from filesystem destruction to command obfuscation. I've provided a few suggestions to refine some of the regular expressions for improved accuracy and broader coverage. Overall, this is a strong security enhancement.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds additional rule-based tool-guard detections to block or prompt on a broader set of destructive / high-risk shell command patterns.
Changes:
- Extend
dangerous_shell_commands.yamlwith new detection rules for filesystem destruction, destructive Git operations, fork bombs/DoS, pipe-to-shell loaders, reverse shells, system tampering, unsafe permissions, and base64-obfuscated execution. - Assign severity/category metadata and remediation guidance per rule.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
|
Please check whether Copilot’s recommendations are worth considering. Thanks for your contribution :) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds additional tool-guard YAML rules to detect and block/prompt on a wider set of destructive or high-risk shell commands executed via execute_shell_command, expanding beyond existing rm/mv guards.
Changes:
- Added new detection rules for filesystem/block-device destruction, destructive Git operations, DoS/fork bombs, pipe-to-shell downloaders, reverse shells, system tampering, unsafe permissions, and base64-obfuscated execution.
- Included severity levels and remediation guidance per rule.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR expands CoPaw’s tool-guard rule set for execute_shell_command by adding YAML-based detection rules for a wider range of destructive or high-risk shell behaviors, aiming to prompt/block unsafe commands before execution.
Changes:
- Added new detection rules for filesystem/device destruction, destructive Git operations, fork bombs, pipe-to-shell downloaders, reverse shells, system tampering, unsafe permissions, and obfuscated execution.
- Assigned severities/categories and provided remediation guidance for each new rule.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR extends CoPaw’s tool-guard rule set to detect and intercept a broader range of destructive or high-risk shell commands (beyond existing rm/mv detection), aiming to prompt/block agent execution before damage occurs.
Changes:
- Added new YAML rules covering filesystem/block device destruction, destructive Git operations, fork bombs / DoS, pipe-to-shell download execution, reverse shells, system tampering, unsafe permissions, and base64-obfuscated execution.
- Annotated each rule with severity, category, patterns, and remediation guidance.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
|
Thanks for the PR. ── Git Data Loss ─────────────────────────────────────────────────────
We find that this rule is not necessary. Please delete this rule and revise the rules to make them more precise. |
…pdate GIT_DATA_LOSS section
There was a problem hiding this comment.
Pull request overview
Adds additional regex-based tool-guard rules to detect potentially destructive execute_shell_command invocations, expanding coverage beyond the existing rm/mv checks.
Changes:
- Expanded
dangerous_shell_commands.yamlwith new rules for filesystem wiping/formatting, fork bombs / DoS patterns, pipe-to-shell loaders, reverse shells, system tampering, unsafe permission changes, and base64-obfuscated execution. - Updated the rule file header documentation to describe the rule system, severity tiers, and taxonomy reference.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds expanded ToolGuard YAML regex rules to detect and intercept potentially destructive execute_shell_command invocations before execution, strengthening the repo’s pre-tool-call security guardrails.
Changes:
- Expanded
dangerous_shell_commands.yamlwith new rule IDs covering disk-wipe/format commands, fork bombs/DoS, pipe-to-shell downloaders, reverse shells, sensitive system file tampering, unsafe permission changes, and base64-piped execution. - Updated the file header commentary to describe severity tiers and taxonomy references.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/copaw/security/tool_guard/rules/dangerous_shell_commands.yaml
Outdated
Show resolved
Hide resolved
|
Thanks again for your revision. According to the Copilot Review, some regular expressions still introduce false positives. Could you please revise them accordingly? |
|
Thanks for the commits. The current rules look good to me. |
Welcome to CoPaw! 🎉Thank you @pzlav for your first contribution! Your PR has been merged. 🚀 We'd love to give you a shout-out in our release notes! If you're comfortable sharing, please reply to this comment with your social media handles using the format below:
Thanks again for helping make CoPaw better! |
discord: 918134357758185492 |
Description
Add YAML detection rules for dangerous shell commands beyond the existing
rmandmvguards. New rules cover filesystem destruction (mkfs, dd), destructive Git operations (reset --hard, push --force), fork bombs, curl|bash pipes, reverse shells, crontab/sudoers tampering, unsafe permissions (chmod 777), and base64-obfuscated execution. Each rule includes severity, pattern matching, and remediation guidance so the user is always prompted or blocked before execution.Related Issue: Fixes #(issue_number) or Relates to #(issue_number)
Security Considerations: These rules are defensive — they add tool_guard rules to prevent agents from executing destructive, privilege-escalating, or obfuscated shell commands without user confirmation. No existing rules are removed or weakened.
Type of Change
Component(s) Affected
Checklist
pre-commit run --all-fileslocally and it passespytestor as relevant) and they passTesting
mkfs /dev/sda,git reset --hard,curl ... | bash) and do not false-positive on safe usage (e.g.git push origin mainwithout--force).TOOL_CMD_DANGEROUS_RMandTOOL_CMD_DANGEROUS_MVrules still work as before.Local Verification Evidence
pytest
====================================== test session starts ======================================
platform linux -- Python 3.10.12, pytest-9.0.2, pluggy-1.6.0
rootdir: /home/pzla/projects/CoPaw
configfile: pyproject.toml
plugins: anyio-4.12.1, asyncio-1.3.0, cov-7.0.0
asyncio: mode=auto, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 64 items
tests/integrated/test_app_startup.py . [ 1%]
tests/integrated/test_version.py ... [ 6%]
tests/test_cli_version.py . [ 7%]
tests/unit/providers/test_anthropic_provider.py ....... [ 18%]
tests/unit/providers/test_default_provider.py .. [ 21%]
tests/unit/providers/test_minimax_provider.py ....... [ 32%]
tests/unit/providers/test_ollama_manager_timeout.py . [ 34%]
tests/unit/providers/test_ollama_provider.py .............. [ 56%]
tests/unit/providers/test_openai_provider.py ........... [ 73%]
tests/unit/providers/test_openai_stream_toolcall_compat.py .. [ 76%]
tests/unit/providers/test_provider_manager.py ............... [100%]
====================================== 64 passed in 9.17s =======================================